<?php

/* @var $this \yii\web\View */
/* @var $content string */

use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use frontend\assets\AppAsset;
use common\widgets\Alert;

AppAsset::register($this);
//echo Yii::$app->user->identity->head_img;die;
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
    <meta charset="<?= Yii::$app->charset ?>">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <?php $this->registerCsrfMetaTags() ?>
    <title><?= Html::encode($this->title) ?></title>
    <?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>

<div class="wrap">
    <?php
    NavBar::begin([
        'brandLabel' => YII::t('common','Blog'),
        'brandUrl' => Yii::$app->homeUrl,
        'options' => [
            'class' => 'navbar-inverse navbar-fixed-top',
        ],
    ]);
    $leftMenus = [
        ['label' => YII::t('common','首页'), 'url' => ['/site/index']],
        ['label' => YII::t('common','文章'), 'url' => ['/posts/index']],
//        ['label' => YII::t('common','我的博客'), 'url' => ['/posts/mylist']],
//        ['label' => YII::t('common','Contact'), 'url' => ['/site/contact']],
    ];
    if (Yii::$app->user->isGuest) {
        $rightMenus[] = ['label' => YII::t('common','Signup'), 'url' => ['/site/signup']];
        $rightMenus[] = ['label' => YII::t('common','Login'), 'url' => ['/site/login']];
    } else {
//        $rightMenus[] = '<li>'
//            . Html::beginForm(['/site/logout'], 'post')
//            . Html::submitButton(
////                'Logout (' . Yii::$app->user->identity->username . ')',
//                '<img src="'.(Yii::$app->user->identity->head_img?:"/statics/images/avatar/small.jpg").'" class="logoutimg" alt="'.Yii::$app->user->identity->username.'">',
//                ['class' => 'btn btn-link logout'],
//                ['items'=>
//                    ['label'=>'退出',
//                    'url'=>['/site/logout'],
//                    'linkOptions'=>['data-method'=>'post']]]
//            )
//            . Html::endForm()
//            . '</li>';
        $rightMenus = [
            ['label' => YII::t('common','我的博客'), 'url' => ['/posts/mylist']],

        ];
        $rightMenus[] = [
                'label'=>'<img src="'.(Yii::$app->user->identity->head_img?:"/statics/images/avatar/small.jpg").'" class="logoutimg" alt="'.Yii::$app->user->identity->username.'">',
                'linkOptions'=>['class'=>'avatar'],
                'items'=>[
                        ['label'=>'个人资料','url'=>['/member/edit'],'linkOptions'=>['data-method'=>'get']],
                        ['label'=>'重置密码','url'=>['/member/setpwd'],'linkOptions'=>['data-method'=>'get']],
                        ['label'=>'退出','url'=>['/site/logout'],'linkOptions'=>['data-method'=>'post']],
                ]
            ];

    }
    echo Nav::widget([
        'options' => ['class' => 'navbar-nav navbar-left'],
        'items' => $leftMenus,
    ]);
    echo Nav::widget([
        'options' => ['class' => 'navbar-nav navbar-right'],
        'encodeLabels'=>false,
        'items' => $rightMenus,
    ]);
    NavBar::end();
    ?>

    <div class="container">
        <?= Breadcrumbs::widget([
            'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
        ]) ?>
        <?= Alert::widget() ?>
        <?= $content ?>
    </div>
</div>

<footer class="footer">
    <div class="container">
        <p class="pull-left">&copy; <?= Html::encode(Yii::$app->name) ?> <?= date('Y') ?></p>

        <p class="pull-right"><?= Yii::powered() ?></p>
    </div>
</footer>

<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
